Page({
    data: {
      params: {
        userId: wx.getStorageSync('userId')
      },
      userHeadPortraitPath: '',//用户头像
      nickName: '',
      userTel: ''
    },
  //接口部分

  //获取用户信息
  getUserinfo(params) {
    var _this = this
    wx.request({
      url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/user/infos/auth',
      data: params,
      method: 'POST',
      header: {
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
      "token" : wx.getStorageSync('token'),
        "uid" : wx.getStorageSync('uuid')
      },
      success: (res) => {
        if (res.data.code == 200) {
          _this.setData({
            users: res.data.data,
            userHeadPortraitPath: res.data.data.userHeadPortraitPath,
            nickName: res.data.data.name,
            userTel: res.data.data.userTel
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }
      }
    })
  },


  //绑定手机号
  bindUsertel (e) {
    console.log(e)

    var userTel = e.detail.value

    this.setData({
      userTel: userTel
    })
  },


  // 绑定手机号
  buyBook () {
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;

  if (!myreg.test(this.data.userTel)) {
    wx.showToast({
      title: '请输入正确的手机号',
      icon: 'none'
    })
    return false
  }

  this.userTelApi(this.data.userTel)

  },


  userTelApi (userTel) {
      var params = {
        userTel: userTel
      }
      wx.request({
        url: 'https://devapi.xiaoshitimebank.com/user/sdx/sdx/user/modify/auth',
        data: params,
        method: 'POST',
        header: {
          "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
          "token": wx.getStorageSync('token'),
          "uid": wx.getStorageSync('uuid')
        },
        success: (res) => {
          if (res.data.success) {
            wx.showToast({
              title: '绑定成功',
              icon: 'none',
              duration: 2000
            })
            setTimeout(function () {
              wx.navigateBack()
            },2000)
          }else{
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        }
      })
  },

  onShow () {
    this.getUserinfo(this.params)
  }
})
